package com.cheyunkeji.er.fragment.evaluate;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.Constants;
import com.cheyun.netsalev3.MyApplication;
import com.cheyunkeji.er.activity.evaluate.CarFrameworkBCSM;
import com.cheyunkeji.er.activity.evaluate.CarFrameworkBZSM;
import com.cheyunkeji.er.activity.evaluate.EvaluateWorkflowActivity;
import com.cheyunkeji.er.base.BaseFragment;
import com.cheyunkeji.er.bean.evaluate.EvaluateDetailResult2;
import com.cheyunkeji.er.http.ApiClient;
import com.cheyunkeji.er.http.RespCallback;
import com.cheyunkeji.er.utils.BitmapUtils;
import com.cheyunkeji.er.view.SToast;
import com.cheyunkeji.er.view.evaluate.CarFrameworkCheckItemView;
import com.cheyunkeji.er.view.evaluate.CarProblemStateSelectDialog;
import com.cheyunkeji.er.view.evaluate.ColourImageBaseLayerView;
import com.google.gson.Gson;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Request;

/**
 * Created by Michael on 2017/4/5 11:03.
 */

public class CarFrameworkCheckFragment extends BaseFragment implements CarProblemStateSelectDialog.onResultSelectedListener, EvaluateWorkflowActivity.OnOutActionListener, ColourImageBaseLayerView.OnColorAreaTouchedListener {

    public static final int PAGE_INDEX = 4;
    private static final String TAG = CarFrameworkCheckFragment.class.getSimpleName();
    private static final int REQUEST_CODE_BZSM = 0x0010;
    @BindView(R.id.rl_img_level_container)
    RelativeLayout rlImgLevelContainer;
    @BindView(R.id.cfciv_1)
    CarFrameworkCheckItemView cfciv1;
    @BindView(R.id.cfciv_2)
    CarFrameworkCheckItemView cfciv2;
    @BindView(R.id.cfciv_3)
    CarFrameworkCheckItemView cfciv3;
    @BindView(R.id.cfciv_4)
    CarFrameworkCheckItemView cfciv4;
    @BindView(R.id.cfciv_5)
    CarFrameworkCheckItemView cfciv5;
    @BindView(R.id.cfciv_6)
    CarFrameworkCheckItemView cfciv6;
    @BindView(R.id.cfciv_7)
    CarFrameworkCheckItemView cfciv7;
    @BindView(R.id.cfciv_8)
    CarFrameworkCheckItemView cfciv8;
    @BindView(R.id.cfciv_9)
    CarFrameworkCheckItemView cfciv9;
    @BindView(R.id.cfciv_10)
    CarFrameworkCheckItemView cfciv10;
    @BindView(R.id.cfciv_11)
    CarFrameworkCheckItemView cfciv11;
    @BindView(R.id.cfciv_12)
    CarFrameworkCheckItemView cfciv12;
    @BindView(R.id.cfciv_13)
    CarFrameworkCheckItemView cfciv13;
    @BindView(R.id.cfciv_14)
    CarFrameworkCheckItemView cfciv14;
    @BindView(R.id.cfciv_15)
    CarFrameworkCheckItemView cfciv15;
    @BindView(R.id.rl_bzsm)
    RelativeLayout rlBzsm;
    @BindView(R.id.rl_bcsm)
    RelativeLayout rlBcsm;
    @BindView(R.id.tv_previous_step)
    TextView tvPreviousStep;
    @BindView(R.id.tv_next_step)
    TextView tvNextStep;
    //    @BindView(R.id.iv_base)
//    ImageView ivBase;
    @BindView(R.id.iv_layer_container)
    ColourImageBaseLayerView ivContainer;
    CarProblemStateSelectDialog stateSelectDialog;
    //    //    Error area ImagView list
//    private ArrayList<ImageView> imgList;
    //    如果再次评估，则会有数据传递过来，如果有评估的第0项（车体左右对称），则进行保存，并传递到备注说明页面
    private EvaluateDetailResult2.DetectionBean.BodyframeBean item0 = null;

    private List<CarFrameworkCheckItemView> itemViewList = null;
    private List<Integer> rbID = null;
    private String[] problemDesc = null;

    private Bitmap[] bitmaps = null;

    private int[] errorImgIdList = new int[]{R.drawable.er_frame_base, R.drawable.er_frame_part_1, R.drawable.er_frame_part_2, R.drawable.er_frame_part_3, R.drawable.er_frame_part_4, R.drawable.er_frame_part_5,
            R.drawable.er_frame_part_6, R.drawable.er_frame_part_7, R.drawable.er_frame_part_8, R.drawable.er_frame_part_9, R.drawable.er_frame_part_10, R.drawable.er_frame_part_11,
            R.drawable.er_frame_part_12, R.drawable.er_frame_part_13, R.drawable.er_frame_part_14, R.drawable.er_frame_part_15};

    private int[] normalImgIdList = new int[]{R.drawable.er_frame_base, R.drawable.er_frame_part_1_normal, R.drawable.er_frame_part_2_normal, R.drawable.er_frame_part_3_normal, R.drawable.er_frame_part_4_normal, R.drawable.er_frame_part_5_normal,
            R.drawable.er_frame_part_6_normal, R.drawable.er_frame_part_7_normal, R.drawable.er_frame_part_8_normal, R.drawable.er_frame_part_9_normal, R.drawable.er_frame_part_10_normal, R.drawable.er_frame_part_11_normal,
            R.drawable.er_frame_part_12_normal, R.drawable.er_frame_part_13_normal, R.drawable.er_frame_part_14_normal, R.drawable.er_frame_part_15_normal,};

    //    保存所有的15条数据项的list
    private List<EvaluateDetailResult2.DetectionBean.BodyframeBean> bodyFrame;
    private Runnable mTask;

    @Override
    protected void doInflaterView(LayoutInflater inflater, ViewGroup container) {
        contentView = inflater.inflate(R.layout.er_frag_car_framework_check2, container, false);
        ButterKnife.bind(this, contentView);
    }

    @Override
    protected void init() {

        initBitmapLayers();
        ivContainer.setListener(this);

    }

    private void initBitmapLayers() {

        if (null == bitmaps || bitmaps.length == 0) {

            bitmaps = new Bitmap[normalImgIdList.length];
            for (int i = 0; i < normalImgIdList.length; i++) {
                bitmaps[i] = BitmapUtils.decodeSampledBitmapFromResource(getActivity(), normalImgIdList[i]);
            }
            ivContainer.setBitmaps(bitmaps);
        }
    }

    @Override
    protected void initView() {

        cfciv1.setOnClickListener(this);
        cfciv2.setOnClickListener(this);
        cfciv3.setOnClickListener(this);
        cfciv4.setOnClickListener(this);
        cfciv5.setOnClickListener(this);
        cfciv6.setOnClickListener(this);
        cfciv7.setOnClickListener(this);
        cfciv8.setOnClickListener(this);
        cfciv9.setOnClickListener(this);
        cfciv10.setOnClickListener(this);
        cfciv11.setOnClickListener(this);
        cfciv12.setOnClickListener(this);
        cfciv13.setOnClickListener(this);
        cfciv14.setOnClickListener(this);
        cfciv15.setOnClickListener(this);

        rlBcsm.setOnClickListener(this);
        rlBzsm.setOnClickListener(this);
        tvPreviousStep.setOnClickListener(this);
        tvNextStep.setOnClickListener(this);

        stateSelectDialog = new CarProblemStateSelectDialog(getActivity(), true, this);

    }

    @Override
    protected void initData() {

        if (null == rbID) {
            rbID = new ArrayList<>();
            rbID.add(R.id.rb_none);
            rbID.add(R.id.rb_bian);
            rbID.add(R.id.rb_qu);
            rbID.add(R.id.rb_huan);
            rbID.add(R.id.rb_han);
            rbID.add(R.id.rb_zhou);
            rbID.add(R.id.rb_xiu);
        }

        if (null == problemDesc) {
            problemDesc = new String[]{"变形", "扭曲", "更换", "烧焊", "褶皱", "修理"};
        }

        if (null == itemViewList) {
            itemViewList = new ArrayList<>();
            itemViewList.add(cfciv1);
            itemViewList.add(cfciv2);
            itemViewList.add(cfciv3);
            itemViewList.add(cfciv4);
            itemViewList.add(cfciv5);
            itemViewList.add(cfciv6);
            itemViewList.add(cfciv7);
            itemViewList.add(cfciv8);
            itemViewList.add(cfciv9);
            itemViewList.add(cfciv10);
            itemViewList.add(cfciv11);
            itemViewList.add(cfciv12);
            itemViewList.add(cfciv13);
            itemViewList.add(cfciv14);
            itemViewList.add(cfciv15);
        }


        if (null != MyApplication.getInstance().getEvaluateResult() && null != MyApplication.getInstance().getEvaluateResult().getDetection()) {
            displayInfo();
        }
    }

    @Override
    public void onResume() {
        super.onResume();

    }

    private void displayInfo() {

        EvaluateDetailResult2.DetectionBean detection = MyApplication.getInstance().getEvaluateResult().getDetection();

        if (null != detection && null != detection.getBodyframe()) {

            if (detection.getBodyframe().size() != 0) {

                bodyFrame = detection.getBodyframe();

                for (int i = 0; i < detection.getBodyframe().size(); i++) {

                    if (detection.getBodyframe().get(i).getId() == 0) {
                        /**
                         * 1.新建评估记录时，没有第0条“车体左右对称”数据，只有在备注说明中增加了备注，才创建该条数据并上传保存
                         * 2.再次对该条记录进行评估时，如果有第0条数据，进入备注说明界面时需要传递过去进行显示
                         */
                        item0 = bodyFrame.get(i);
                        continue;
                    } else {
                        switchItemTextDesc(itemViewList.get(detection.getBodyframe().get(i).getId() - 1), rbID.get(detection.getBodyframe().get(i).getStatus()), bodyFrame.get(i).getMark());
                        showErrorImg(itemViewList.get(detection.getBodyframe().get(i).getId() - 1),
                                rbID.get(detection.getBodyframe().get(i).getStatus()));
                    }
                }
            }
        }

    }


    @Override
    public void onClick(View v) {
        super.onClick(v);

        switch (v.getId()) {

            case R.id.cfciv_1:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_1);
                break;
            case R.id.cfciv_2:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_2);
                break;
            case R.id.cfciv_3:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_3);
                break;
            case R.id.cfciv_4:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_4);
                break;
            case R.id.cfciv_5:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_5);
                break;

            case R.id.cfciv_6:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_6);
                break;
            case R.id.cfciv_7:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_7);
                break;
            case R.id.cfciv_8:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_8);
                break;
            case R.id.cfciv_9:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_9);
                break;
            case R.id.cfciv_10:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_10);
                break;
            case R.id.cfciv_11:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_11);
                break;
            case R.id.cfciv_12:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_12);
                break;
            case R.id.cfciv_13:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_13);
                break;
            case R.id.cfciv_14:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_14);
                break;
            case R.id.cfciv_15:
                stateSelectDialog.show();
                stateSelectDialog.setTag(R.id.cfciv_15);
                break;

            case R.id.rl_bcsm:
                startActivity(new Intent(getActivity(), CarFrameworkBCSM.class));
                break;

            case R.id.rl_bzsm:

                Intent intent = new Intent(getActivity(), CarFrameworkBZSM.class);
                intent.putExtra("FRAMEWORK_CHECK_ITEMS", (Serializable) getResult());
                this.startActivityForResult(intent, REQUEST_CODE_BZSM);

                break;

            case R.id.tv_next_step:
                onSaveEvaluateResult(new Runnable() {
                    @Override
                    public void run() {
                        goToNextPage();
                    }
                });
                break;

            case R.id.tv_previous_step:
                onSaveEvaluateResult(new Runnable() {
                    @Override
                    public void run() {
                        goToPreviousPage();
                    }
                });
                break;

            default:
                break;
        }
    }

    //    Dialog 确定按钮回调
    @Override
    public void onConfirm(int checkedRadioButtonId) {

        switch ((Integer) stateSelectDialog.getTag()) {

            case R.id.cfciv_1:
                switchItemTextDesc(cfciv1, checkedRadioButtonId, "");
                showErrorImg(cfciv1, checkedRadioButtonId);
                break;
            case R.id.cfciv_2:
                switchItemTextDesc(cfciv2, checkedRadioButtonId, "");
                showErrorImg(cfciv2, checkedRadioButtonId);
                break;
            case R.id.cfciv_3:
                switchItemTextDesc(cfciv3, checkedRadioButtonId, "");
                showErrorImg(cfciv3, checkedRadioButtonId);
                break;
            case R.id.cfciv_4:
                switchItemTextDesc(cfciv4, checkedRadioButtonId, "");
                showErrorImg(cfciv4, checkedRadioButtonId);
                break;
            case R.id.cfciv_5:
                switchItemTextDesc(cfciv5, checkedRadioButtonId, "");
                showErrorImg(cfciv5, checkedRadioButtonId);
                break;
            case R.id.cfciv_6:
                switchItemTextDesc(cfciv6, checkedRadioButtonId, "");
                showErrorImg(cfciv6, checkedRadioButtonId);
                break;
            case R.id.cfciv_7:
                switchItemTextDesc(cfciv7, checkedRadioButtonId, "");
                showErrorImg(cfciv7, checkedRadioButtonId);
                break;
            case R.id.cfciv_8:
                switchItemTextDesc(cfciv8, checkedRadioButtonId, "");
                showErrorImg(cfciv8, checkedRadioButtonId);
                break;
            case R.id.cfciv_9:
                switchItemTextDesc(cfciv9, checkedRadioButtonId, "");
                showErrorImg(cfciv9, checkedRadioButtonId);
                break;
            case R.id.cfciv_10:
                switchItemTextDesc(cfciv10, checkedRadioButtonId, "");
                showErrorImg(cfciv10, checkedRadioButtonId);
                break;
            case R.id.cfciv_11:
                switchItemTextDesc(cfciv11, checkedRadioButtonId, "");
                showErrorImg(cfciv11, checkedRadioButtonId);
                break;
            case R.id.cfciv_12:
                switchItemTextDesc(cfciv12, checkedRadioButtonId, "");
                showErrorImg(cfciv12, checkedRadioButtonId);
                break;
            case R.id.cfciv_13:
                switchItemTextDesc(cfciv13, checkedRadioButtonId, "");
                showErrorImg(cfciv13, checkedRadioButtonId);
                break;
            case R.id.cfciv_14:
                switchItemTextDesc(cfciv14, checkedRadioButtonId, "");
                showErrorImg(cfciv14, checkedRadioButtonId);
                break;
            case R.id.cfciv_15:
                switchItemTextDesc(cfciv15, checkedRadioButtonId, "");
                showErrorImg(cfciv15, checkedRadioButtonId);
                break;

            default:
                break;
        }
    }


    private void showErrorImg(CarFrameworkCheckItemView cfciv, int checkedRadioButtonId) {

        if (checkedRadioButtonId == R.id.rb_none) {

            if (cfciv.hasFaultColorAdded()) {
                bitmaps[itemViewList.indexOf(cfciv) + 1] = BitmapUtils.decodeSampledBitmapFromResource(getActivity(), normalImgIdList[itemViewList.indexOf(cfciv) + 1]);
                cfciv.sethasFaultColorAdded(false);
            }
        } else {

            if (!cfciv.hasFaultColorAdded()) {
                bitmaps[itemViewList.indexOf(cfciv) + 1] = BitmapUtils.decodeSampledBitmapFromResource(getActivity(), errorImgIdList[itemViewList.indexOf(cfciv) + 1]);
                cfciv.sethasFaultColorAdded(true);
            }
        }
        ivContainer.setBitmaps(bitmaps);
    }

    //    Dialog 取消按钮回调
    @Override
    public void onCancel() {

    }

    public void switchItemTextDesc(CarFrameworkCheckItemView view, int checkedRadioId, String mark) {

        switch (checkedRadioId) {

            case R.id.rb_none:
                view.showItemProblem("无", false);
                break;
            case R.id.rb_bian:
                view.showItemProblem(problemDesc[0], true);
                break;
            case R.id.rb_qu:
                view.showItemProblem(problemDesc[1], true);
                break;
            case R.id.rb_huan:
                view.showItemProblem(problemDesc[2], true);
                break;
            case R.id.rb_han:
                view.showItemProblem(problemDesc[3], true);
                break;
            case R.id.rb_zhou:
                view.showItemProblem(problemDesc[4], true);
                break;
            case R.id.rb_xiu:
                view.showItemProblem(problemDesc[5], true);
                break;

            default:
                break;
        }

        if (null == view.getTag())
            view.setTag(new EvaluateDetailResult2.DetectionBean.BodyframeBean(itemViewList.indexOf(view) + 1, rbID.indexOf(checkedRadioId), mark));
        else {
            ((EvaluateDetailResult2.DetectionBean.BodyframeBean) view.getTag()).setId(itemViewList.indexOf(view) + 1);
            ((EvaluateDetailResult2.DetectionBean.BodyframeBean) view.getTag()).setStatus(rbID.indexOf(checkedRadioId));
            ((EvaluateDetailResult2.DetectionBean.BodyframeBean) view.getTag()).setMark(mark);
        }
    }

    @Override
    public void onSaveEvaluateResult(Runnable task) {

        if (null != task) {
            this.mTask = task;
        }

        String myData = new StringBuilder("{\"bodyframe\":").append(new Gson().toJson(getResult())).append("}").toString();


        HashMap<String, String> params = new HashMap<>();
        //      params.put("authkey", UserInfoManager.getInstance(MyApplication.getInstance()).getAuthKey());//        params.put(ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getYkey(), ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getY7e_e73a691f02a46500201c3998e6a2989d());
        params.put("aid", MyApplication.getInstance().getEvaluateResult().getAid());

        params.put("detection", myData);

        if (MyApplication.getInstance().getEvaluateResult() == null || MyApplication.getInstance().getEvaluateResult().getIroute() == null || MyApplication.getInstance().getEvaluateResult().getIroute().size() == 0) {
            int[] iroute = new int[15];
            iroute[PAGE_INDEX] = 1;
            String json = new Gson().toJson(iroute);
            Log.e(TAG, "saveData: 评估记录为空或数组为空时 保存记录数组 ：  " + json.substring(1, json.length() - 1));
            params.put("iroute", json.substring(1, json.length() - 1));
        } else {
            MyApplication.getInstance().getEvaluateResult().getIroute().set(PAGE_INDEX, 1);
            String json = new Gson().toJson(MyApplication.getInstance().getEvaluateResult().getIroute());
            params.put("iroute", json.substring(1, json.length() - 1));
            Log.e(TAG, "saveData:  保存记录数组 ：记录非空并且数组非空时 保存记录数组 ：   " + json.substring(1, json.length() - 1));
        }

        //        根据评估类型进行保存或编辑
        int evaluateType = ((EvaluateWorkflowActivity) getActivity()).getEvaluateArchiveType();

//       保存新创建、未上传待评估数据
        if (evaluateType == Constants.ARCHIVE_TYPE_CREATE_NEW_EVALUATE || evaluateType == Constants.ARCHIVE_TYPE_UN_UPLOAD_TO_EVALUATE || evaluateType == Constants.ARCHIVE_TYPE_WITH_FAST_EVALUATE_VIN) {

            ApiClient.postForm(((EvaluateWorkflowActivity) getActivity()).getCURRENT_TO_UPLOAD_RESULT_URL(), params, new RespCallback<EvaluateDetailResult2>() {

                @Override
                protected void onRequestFailed(String msg) {
                    SToast.show(msg);
                    if (mTask instanceof EvaluateWorkflowActivity.ExitRunnable) {
                        mTask.run();
                        mTask = null;
                    }
                }

                @Override
                protected void onSuccess(EvaluateDetailResult2 data) {

                    if (null != data) {

                        MyApplication.getInstance().setEvaluateResult(data);

                        if (null != mTask) {
                            mTask.run();
                            mTask = null;
                        }
                    }
                }

                @Override
                public void onBefore(Request request, int id) {
                    showDialog();
                }

                @Override
                public void onAfter(int id) {
                    dismissDialog();
                }
            });

        } else if (evaluateType == Constants.ARCHIVE_TYPE_UPLOADED_TO_EDIT) {

            ApiClient.postForm(((EvaluateWorkflowActivity) getActivity()).getCURRENT_TO_UPLOAD_RESULT_URL(), params, new StringCallback() {
                @Override
                public void onError(Call call, Exception e, int id) {

                    // 网络异常
                    if (e instanceof UnknownHostException || e instanceof SocketException) {
                        SToast.show(R.string.tip_network_error, Gravity.CENTER);
                        return;
                    }
                }

                @Override
                public void onResponse(String response, int id) {

                    try {

                        JSONObject obj = new JSONObject(response);
                        if (obj.optInt("code") == 1) {
//                            SToast.show("保存成功", Gravity.CENTER);

                            Log.e(TAG, "onResponse: 编辑成功 : " + obj.optString("data"));

                            if (null != mTask) {
                                mTask.run();
                                mTask = null;
                            }

                        } else {
                            SToast.show( obj.optString("msg") );
                            if (mTask instanceof EvaluateWorkflowActivity.ExitRunnable) {
                                mTask.run();
                                mTask = null;
                            }
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onBefore(Request request, int id) {
                    showDialog();
                }

                @Override
                public void onAfter(int id) {
                    dismissDialog();
                }
            });
        }
    }

    private void goToNextPage() {
        ((EvaluateWorkflowActivity) getActivity()).setCurrentPage(AppearanceCheckFragment.PAGE_INDEX);
    }

    private void goToPreviousPage() {
        ((EvaluateWorkflowActivity) getActivity()).setCurrentPage(TakeCarPhotoFragment.PAGE_INDEX);
    }


    public List<EvaluateDetailResult2.DetectionBean.BodyframeBean> getResult() {

        if (null == bodyFrame)
            bodyFrame = new ArrayList<>();
        else
            bodyFrame.clear();

        for (int i = 0; i < itemViewList.size(); i++) {
            if (null != itemViewList.get(i).getTag()) {
                bodyFrame.add((EvaluateDetailResult2.DetectionBean.BodyframeBean) itemViewList.get(i).getTag());
            }
        }

        if (null != item0) {
            bodyFrame.add(0, item0);
        }

        Gson gson = new Gson();
        Log.e(TAG, "onSaveEvaluateResult: getResult :　" + gson.toJson(bodyFrame));

        return bodyFrame;

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE_BZSM) {

            bodyFrame = (List<EvaluateDetailResult2.DetectionBean.BodyframeBean>) data.getSerializableExtra("FRAMEWORK_CHECK_ITEMS");

            Log.e(TAG, "onActivityResult:  Result Data : " + new Gson().toJson(bodyFrame));

            for (int i = 0; i < bodyFrame.size(); i++) {

                if (bodyFrame.get(i).getId() == 0) {
                    item0 = bodyFrame.get(i);
                } else {
                    itemViewList.get(bodyFrame.get(i).getId() - 1).setTag(bodyFrame.get(i));
                }
            }
        }
    }


    @Override
    public void onAreaTouched(int areaIndex) {

        stateSelectDialog.show();
        stateSelectDialog.setTag(itemViewList.get(areaIndex - 1).getId());

    }

}
